package com.eqxiu.ieditor.manager.controller;

import com.eqxiu.ieditor.weixin.api.WeixinMenuServiceApi;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
@RequestMapping("/m/ie/test")
public class TestController {

	@Resource
	private WeixinMenuServiceApi weixinMenuServiceApi;

    private static final String WEIXIN_MENU_URL = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=";

	@GetMapping(value = "/test", produces = "application/json; charset=UTF-8")
	public String index() {
		System.out.println("------------------------------------");
		String s = weixinMenuServiceApi.findWeixinMenuList();
        System.out.println(s);
		return s;
	}

	@GetMapping("/test2")
	public String index2() {

        RestTemplate restTemplate = new RestTemplate();
        String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=ZcQFMNl-2O7yQ6bP3DnGoy5Fe9OiZYuNHWJRfJHLE5g3kr93jxKUmqvbil7nt6hr8hCH-t5LImEbUMqgcRg78HhouqgnfC3OQYWkClwHUDZaR5NZyrOeWbWNEs4u60_4PDRgCAADRF";
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);

        HttpEntity<String> request = new HttpEntity<>(this.index(), headers);
        ResponseEntity<String> response = restTemplate.postForEntity( url, request , String.class);
        String body = response.getBody();
        System.out.println(body);
        return body;
	}





}
